﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;

namespace OrionBank.Classe
{
    class Operations
    {
        public int Id { get; set; }
        public DateTime Date { get; set; }
        public string Tiers { get; set; }
        public string Libelle { get; set; }
        public double Montant { get; set; }
        public DateTime? DatePointage { get; set; }
        public int IdModePaiement { get; set; }
        public int IdCategorie { get; set; }
        public int IdCompte { get; set; }

        static public List<Classe.Operations> ChargeTout(Int32 idCompte)
        {
            List<Classe.Operations> ls = new List<Operations>();
            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    ls = OrionBank.Classe.SQLite.Operations.ChargeTout(idCompte);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }
            return ls;
        }

        static public double SoldeCompteAt(DateTime dt, Int32 idC)
        {
            double retour = 0.0;
            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.SoldeCompteAt(dt, idC);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }
            return retour;
        }

        static public DateTime GetMaxDate(Int32 idC)
        {
            DateTime retour = DateTime.Now;
            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.GetMaxDate(idC);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }
            return retour;
        }

        static public DateTime GetMinDate(Int32 idC)
        {
            DateTime retour = DateTime.Now;
            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.GetMinDate(idC);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }
            return retour;
        }

        static public void Sauve(Classe.Operations o)
        {
            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    OrionBank.Classe.SQLite.Operations.Sauve(o);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }
        }

        static public List<String> ChargeToutTiers(Int32 idCompte)
        {
            List<String> ls = new List<String>();
            
            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    ls = OrionBank.Classe.SQLite.Operations.ChargeToutTiers(idCompte);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }
            
            return ls;
        }

        static public double CalculAVenir(Int32 idCompte)
        {
            double retour = 0.0;

            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.CalculAVenir(idCompte);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }

            return retour;
        }

        static public double CalculSoldOpePoint(Int32 idCompte)
        {
            double retour = 0.0;

            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.CalculSoldOpePoint(idCompte);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }

            return retour;
        }

        static public void Maj(Classe.Operations o)
        {
            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    OrionBank.Classe.SQLite.Operations.Maj(o);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }
        }

        static public List<string[]> GroupByTiers(Int32 idC)
        {
            List<string[]> retour = new List<string[]>();

            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.GroupByTiers(idC);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }

            return retour;
        }

        static public List<string[]> GroupByTiersDC(Int32 idC)
        {
            List<string[]> retour = new List<string[]>();

            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.GroupByTiersDC(idC);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }

            return retour;
        }

        static public List<string[]> GroupByCategories(Int32 idC)
        {
            List<string[]> retour = new List<string[]>();

            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.GroupByCategories(idC);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }

            return retour;
        }

        static public List<string[]> GroupByCategoriesDC(Int32 idC)
        {
            List<string[]> retour = new List<string[]>();

            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.GroupByCategoriesDC(idC);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }

            return retour;
        }

        static public DataSet ChargeGrilleOperation(Int32 idCompte)
        {
            DataSet retour = new DataSet();

            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.ChargeGrilleOperation(idCompte);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }

            return retour;
        }

        static public DataSet ChargeGrilleOperationFiltre(int idCompte,
                                bool bDate, string cbFiltreDate, DateTime txtFiltreDate,
                                bool bModePaiement, string txtFiltreModePaiement,
                                bool bTiers, string txtFiltreTiers,
                                bool bCategorie, string txtFiltreCategorie,
                                bool bMontant, string cbFiltreMontant, double txtFiltreMontant)
        {
            DataSet retour = new DataSet();

            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.ChargeGrilleOperationFiltre(idCompte,
                                bDate, cbFiltreDate, txtFiltreDate,
                                bModePaiement, txtFiltreModePaiement,
                                bTiers, txtFiltreTiers,
                                bCategorie, txtFiltreCategorie,
                                bMontant, cbFiltreMontant, txtFiltreMontant);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }

            return retour;
        }

        static public List<Classe.Operations> ChargeGrilleListeOperation(Int32 idCompte)
        {
            List<Classe.Operations> retour = new List<Classe.Operations>();

            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    retour = OrionBank.Classe.SQLite.Operations.ChargeGrilleListeOperation(idCompte);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }

            return retour;
        }

        static public Operations Charge(int id)
        {
            Operations o = new Operations();
            
            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    o = OrionBank.Classe.SQLite.Operations.Charge(id);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }
            
            return o;
        }

        static public void Delete(int id)
        {
            switch (ConfigurationManager.AppSettings["typeConnection"])
            {
                case Configuration.BD_SQLITE:
                    OrionBank.Classe.SQLite.Operations.Delete(id);
                    break;
                default:
                    throw new Exception(String.Format("Ce mode de connection({0}) n'est pas autorisé.", ConfigurationManager.AppSettings["typeConnection"]));
            }
        }
    }
}
